﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class CikisEmirleri : XForm
    {
        public CikisEmirleri()
        {
            InitializeComponent();
        }

        BindingSource bscikisEmirleri, bsArtikel, bsRolls,bsFoys;
        private void CikisEmirleri_Load(object sender, EventArgs e)
        {
            
            ds.Merge(Session.DataManager.ExecuteDataSet("GetKumasCikisEmirleri", chkKapanlariGoster.Checked, WhoAmI));

            DataRelation FK_CikisEmri = new DataRelation("FK_CikisEmri",
              ds.Tables["Table"].Columns["CikisEmriId"],
              ds.Tables["Table1"].Columns["CikisEmriId"]);
            ds.Relations.Add(FK_CikisEmri);

            DataRelation FK_ProductIdFoys = new DataRelation("FK_ProductIdFoys",
                        new DataColumn[] { ds.Tables["Table1"].Columns["CikisEmriId"], ds.Tables["Table1"].Columns["ProductId"] },
                        new DataColumn[] { ds.Tables["Table2"].Columns["CikisEmriId"], ds.Tables["Table2"].Columns["ProductId"] });
            ds.Relations.Add(FK_ProductIdFoys);

            DataRelation FK_ProductIdRolls = new DataRelation("FK_ProductIdRolls",
                        new DataColumn[] { ds.Tables["Table1"].Columns["CikisEmriId"], ds.Tables["Table1"].Columns["ProductId"] },
                        new DataColumn[] { ds.Tables["Table3"].Columns["CikisEmriId"], ds.Tables["Table3"].Columns["ProductId"] });
            ds.Relations.Add(FK_ProductIdRolls);

            bscikisEmirleri = new BindingSource(ds, "Table");
            bsArtikel = new BindingSource(bscikisEmirleri, "FK_CikisEmri");
            bsFoys = new BindingSource(bsArtikel, "FK_ProductIdFoys");
            bsRolls = new BindingSource(bsArtikel, "FK_ProductIdRolls");

            InitGridView(gvCikisEmirleri, bscikisEmirleri);
            InitGridView(gvArtikel, bsArtikel);
            InitGridView(gvFoys, bsFoys);
            InitGridView(gvRolls, bsRolls);

            //gvCikisEmirleri.Init("[GetKumasCikisEmirleri]", chkKapanlariGoster.Checked, WhoAmI);
            //gvCikisEmirleri.AddDetailGrid(gvArtikel, "CikisEmriId");
            //gvArtikel.AddDetailGrid(gvFoys, "CikisEmriId,ProductId");
            //gvArtikel.AddDetailGrid(gvRolls, "CikisEmriId,ProductId");

            gvArtikel.MakeColumnInvisible("CikisEmriId");
            gvFoys.MakeColumnInvisible("Scan", "ProductId","CikisEmriId");
            gvRolls.MakeColumnInvisible("CikisEmriId", "ProductId", "Scan");

            gvCikisEmirleri.AddSummary();
            gvArtikel.AddSummary("CikilacakMiktar");
            gvFoys.AddSummary("Total", "Ihtiyac");
            gvRolls.AddSummary("Qty");

            chkKapanlariGoster.CheckedChanged += chkKapanlariGoster_CheckedChanged;
            btnUpdate.ItemClick += btnUpdate_ItemClick;
        }

        void chkKapanlariGoster_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ds.Clear();
            ds.Merge(ExecuteDataSet("GetKumasCikisEmirleri", chkKapanlariGoster.Checked, WhoAmI));
        }

        void btnUpdate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
         
            ds.Clear();
            ds.Merge(ExecuteDataSet("GetKumasCikisEmirleri", chkKapanlariGoster.Checked, WhoAmI));
        }

    }
}